FROM docker.fxxk.dedyn.io/node:22.2.0-slim AS build-stage
RUN npm config set registry https://registry.npmmirror.com --global
RUN npm install -g pnpm

WORKDIR /buyer
COPY ./buyer .
RUN pnpm build

WORKDIR /seller
COPY ./seller .
RUN pnpm build

WORKDIR /manager
COPY ./manager .
RUN pnpm build

WORKDIR /im
COPY ./im .
RUN pnpm build

# production stage
FROM nginx:stable AS production-stage
COPY ./start-nginx.sh /usr/bin/start-nginx.sh
RUN chmod +x /usr/bin/start-nginx.sh

COPY --from=build-stage /buyer/dist /usr/share/nginx/html/buyer
COPY --from=build-stage /seller/dist /usr/share/nginx/html/seller
COPY --from=build-stage /manager/dist /usr/share/nginx/html/manager
COPY --from=build-stage /im/dist /usr/share/nginx/html/im
COPY ./nginx.conf /etc/nginx/nginx.conf
EXPOSE 80

CMD ["/bin/sh","/usr/bin/start-nginx.sh"]